const defaultState={
    inputValue:'hello word',
    list:[]
}
export default (state = defaultState,action) => {
    if(action.type === 'change_input_value'){
        //拷贝一份原始的state进行修改
        const newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        return newState;
    }

    if(action.type === 'add_todo_item'){
        //拷贝一份原始的state进行修改
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }

    if(action.type === 'del_todo_item'){
        //拷贝一份原始的state进行修改
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.value,1);
        console.log(newState)
        return newState;
    }

    return state;
}